package cn.uway.config;

import net.sf.ehcache.CacheManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;

import cn.uway.cache.LocalCache;

@Configuration
public class EhcacheConfig {
	
	 String configurationFileName = "classpath:config/ehcache.xml";
	 
	 protected  Logger logger = LoggerFactory.getLogger(this.getClass());
	
	 @Bean
	 public net.sf.ehcache.CacheManager ehcacheManager() {
	        try {
	            net.sf.ehcache.CacheManager manager = net.sf.ehcache.CacheManager.create( ResourceUtils.getURL(configurationFileName));
	            return manager;
	        }
	        catch (Exception e) {
	        	logger.error("初始化 CacheManager 出错", e);
	        }
			return null;
	 }	 	
	 
	 @Bean
     public LocalCache  ehcache( CacheManager  ehcacheManager ) {  
		 LocalCache ehcache = new LocalCache();
		 ehcache.setEhcacheManager(ehcacheManager);
		 return ehcache;
     }  
	 
}
